//
//  LikeTableViewCell.m
//  GOGOTravel
//
//  Created by dllo on 16/1/29.
//  Copyright © 2016年 果果. All rights reserved.
//

#import "LikeTableViewCell.h"
#import "Spot.h"
#import "UIButton+WebCache.h"
@implementation LikeTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createCell];
        
    }
    return self;
}

- (void)setModel:(Spot *)model{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    NSString *str = [_model.recommendations_count stringValue];
    _label.text = [NSString stringWithFormat:@"%@ 人喜欢", str];
    _label.frame = CGRectMake(15, 20, 100, 30);
    NSString *STR = [_model.comments_count stringValue];
    _labelPINGlUN.text = [NSString stringWithFormat:@"%@ 人评论", STR];
    _labelPINGlUN.frame = CGRectMake(15, 150, 100, 30);
}


- (void)layoutSubviews{
    [super layoutSubviews];
    //设置做多显示七个
    if (_count < 7) {
        for (NSInteger i = 1; i <= _count ; i++) {
            self.button = [UIButton buttonWithType:UIButtonTypeCustom];
            _button.frame = CGRectMake(50 * (i - 1) + 10, 80, 40, 40);
            _button.layer.cornerRadius = 20;
            _button.layer.masksToBounds = YES;
            Recommendation *model = _modelArr[i - 1];
            
            [_button sd_setBackgroundImageWithURL:[NSURL URLWithString:model.avatar_l] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:PLACE_HLODER]];
            [self.contentView addSubview:_button];
        }
    }else{
        for (NSInteger i = 1; i <= 7 ; i++) {
            self.button = [UIButton buttonWithType:UIButtonTypeCustom];
            _button.frame = CGRectMake(50 * (i - 1) + 10, 80, 40, 40);
            _button.layer.cornerRadius = 20;
            _button.layer.masksToBounds = YES;
            Recommendation *model = _modelArr[i - 1];
            
            [_button sd_setBackgroundImageWithURL:[NSURL URLWithString:model.avatar_l] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:PLACE_HLODER]];
            [self.contentView addSubview:_button];
    }
    }
}


- (void)createCell {
    self.label = [[UILabel alloc] init];
    [self.contentView addSubview:_label];
    [_label release];
    
    self.labelPINGlUN = [[UILabel alloc] init];
    [self.contentView addSubview:_labelPINGlUN];
    [_labelPINGlUN release];
}




- (void)dealloc{
    [_label release];
    [_modelArr release];
    [_labelPINGlUN release];
    [_model release];
    [_button release];
    [super dealloc];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
